package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.vo.LogiKefuIssueExtVo;
import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiKefuIssueVo;
import com.piggy.logi.sys.bo.LogiKefuIssueQueryBo;
import com.piggy.logi.sys.bo.LogiKefuIssueEditBo;
import com.piggy.logi.sys.service.ILogiKefuIssueService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;

import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 客服问题登记Controller
 *
 * @author piggy
 * @date 2023-10-25
 */
@Api(value = "客服问题登记控制器", tags = {"客服问题登记管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/issue")
public class LogiKefuIssueController extends BaseController {

    private final ILogiKefuIssueService iLogiKefuIssueService;

    /**
     * 查询客服问题登记列表
     */
    @ApiOperation("查询客服问题登记列表")
    //@SaCheckPermission("sys:issue:list")
    @GetMapping("/list")
    public TableDataInfo<LogiKefuIssueExtVo> list(@Validated LogiKefuIssueQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiKefuIssueService.queryPageList(bo);
    }

    /**
     * 获取客服问题登记详细信息
     */
    @ApiOperation("获取客服问题登记详细信息")
    //@SaCheckPermission("sys:issue:query")
    @GetMapping("/{id}")
    public R<LogiKefuIssueVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable("id") Long id) {
        return R.ok(iLogiKefuIssueService.queryById(id));
    }

    /**
     * 新增客服问题登记
     */
    @ApiOperation("新增客服问题登记/回复")
    //@SaCheckPermission("sys:issue:add")
    @Log(title = "客服问题登记/回复", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiKefuIssueExtVo> add(@Validated @RequestBody LogiKefuIssueEditBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return R.ok(iLogiKefuIssueService.insertByAddBo(bo));
    }

    /**
     * 修改客服问题登记
     */
    @ApiOperation("修改客服问题登记")
    //@SaCheckPermission("sys:issue:edit")
    @Log(title = "客服问题登记", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiKefuIssueExtVo> edit(@Validated @RequestBody LogiKefuIssueEditBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return R.ok(iLogiKefuIssueService.updateByEditBo(bo));
    }

    /**
     * 删除客服问题登记
     */
    @ApiOperation("删除客服问题登记")
    //@SaCheckPermission("sys:issue:remove")
    @Log(title = "客服问题登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                             @PathVariable Long[] ids) {
        return R.ok(iLogiKefuIssueService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
